class EventEmitter {
    constructor () {
        _events = []
    }
    on = (evt, fn) => {
        (this._events[evt] || (this._events[evt] = [])).push(fn)
    }
    emit = (evt, ...args) => {
        if (!this._events[evt]) return false
        let fns = this._events[evt]
        fns.forEach(fn => {
            fn.apply(this, args)
        });
        return true
    }
    off = (evt, fn) => {
        if (!fn) {
            this._events[evt].length = 0
        } else {
            let fns = this._events[evt]
            for (let i = 0; i < fns.length; i++) {
                if (fn === fns[i] || fn === fns[i].fn) {
                    fns.splice(i, 1)
                }
            }
        }
    }
    removeAllListener = (evt) => {
        if (evt) {
            this._events[evt].length = 0
        } else {
            this._events = []
        }
    }
}
export const eventEmit = new EventEmitter()